package com.zhongshengnetwork.rightbe.game.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.app.Activity;
import android.os.Handler;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.dd.CircularProgressButton;
import com.tencent.connect.common.Constants;
import com.tencent.connect.share.QQShare;
import com.tencent.connect.share.QzoneShare;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;
import com.wang.avi.AVLoadingIndicatorView;
import com.zhongshengnetwork.rightbe.Constant.APIKey;
import com.zhongshengnetwork.rightbe.CustomApplication;
import com.zhongshengnetwork.rightbe.MainActivity;
import com.zhongshengnetwork.rightbe.R;
import com.zhongshengnetwork.rightbe.common.BroadcastDefine;
import com.zhongshengnetwork.rightbe.common.CommonUtils;
import com.zhongshengnetwork.rightbe.common.GsonTools;
import com.zhongshengnetwork.rightbe.common.TopBarView;
import com.zhongshengnetwork.rightbe.common.activity.AppBaseActivity;
import com.zhongshengnetwork.rightbe.common.customview.ActionSheetDialog;
import com.zhongshengnetwork.rightbe.common.customview.PublishSelectPicPopupWindow;
import com.zhongshengnetwork.rightbe.common.utils.ToastUtil;
import com.zhongshengnetwork.rightbe.game.model.WordModel;
import com.zhongshengnetwork.rightbe.gsonmodel.CommonModel;
import com.zhongshengnetwork.rightbe.gsonmodel.GuessAnswerTipModel;
import com.zhongshengnetwork.rightbe.gsonmodel.WordUserinfoModel;
import com.zhongshengnetwork.rightbe.gsonmodel.WordlistModel;
import com.zhongshengnetwork.rightbe.https.HttpCallBack;
import com.zhongshengnetwork.rightbe.https.HttpsUtils;
import com.zhongshengnetwork.rightbe.login.LoginActivity;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadFactory;

public class CancleWordActivity extends AppBaseActivity implements TopBarView.onTitleBarClickListener{
    private final static String url = "http://a.app.qq.com/o/simple.jsp?pkgname=com.zhongshengnetwork.rightbe";//Constant.HOST+"downapp.do?";
    private final static String content = "成语消消，好玩又益智，赶紧来体验吧~";
    private List<String> list;
    private PublishSelectPicPopupWindow menuWindow;

    private TopBarView topbar;

    private CircularProgressButton cancel_word_firstline_1;
    private CircularProgressButton cancel_word_firstline_2;
    private CircularProgressButton cancel_word_firstline_3;
    private CircularProgressButton cancel_word_firstline_4;
    private CircularProgressButton cancel_word_firstline_5;
    private CircularProgressButton cancel_word_firstline_6;
    private CircularProgressButton cancel_word_firstline_7;

    private CircularProgressButton cancel_word_secondline_1;
    private CircularProgressButton cancel_word_secondline_2;
    private CircularProgressButton cancel_word_secondline_3;
    private CircularProgressButton cancel_word_secondline_4;
    private CircularProgressButton cancel_word_secondline_5;
    private CircularProgressButton cancel_word_secondline_6;
    private CircularProgressButton cancel_word_secondline_7;

    private CircularProgressButton cancel_word_thirdline_1;
    private CircularProgressButton cancel_word_thirdline_2;
    private CircularProgressButton cancel_word_thirdline_3;
    private CircularProgressButton cancel_word_thirdline_4;
    private CircularProgressButton cancel_word_thirdline_5;
    private CircularProgressButton cancel_word_thirdline_6;
    private CircularProgressButton cancel_word_thirdline_7;

    private CircularProgressButton cancel_word_fourthline_1;
    private CircularProgressButton cancel_word_fourthline_2;
    private CircularProgressButton cancel_word_fourthline_3;
    private CircularProgressButton cancel_word_fourthline_4;
    private CircularProgressButton cancel_word_fourthline_5;
    private CircularProgressButton cancel_word_fourthline_6;
    private CircularProgressButton cancel_word_fourthline_7;

    private CircularProgressButton cancel_word_fifthline_1;
    private CircularProgressButton cancel_word_fifthline_2;
    private CircularProgressButton cancel_word_fifthline_3;
    private CircularProgressButton cancel_word_fifthline_4;
    private CircularProgressButton cancel_word_fifthline_5;
    private CircularProgressButton cancel_word_fifthline_6;
    private CircularProgressButton cancel_word_fifthline_7;

    private CircularProgressButton cancel_word_sixthline_1;
    private CircularProgressButton cancel_word_sixthline_2;
    private CircularProgressButton cancel_word_sixthline_3;
    private CircularProgressButton cancel_word_sixthline_4;
    private CircularProgressButton cancel_word_sixthline_5;

    private TextView cancel_word_tip;
    private TextView cancel_word_gold;

    private CircularProgressButton cancel_word_menutip;//提示
    private CircularProgressButton cancel_word_menureset;//求助
    private CircularProgressButton cancel_word_menushare;//分享

    private List<WordModel>textList;
    private List<WordlistModel> wordlistModelList;
    private WordUserinfoModel wordUserinfoModel = null;
    private List<String> answerList;
    private List<Map<String,String>> allAnswerList;
    private boolean isGettingTip = false;
    private boolean isChecking = false;
    private String shareDes = null;
    private AVLoadingIndicatorView avi;
    private RelativeLayout cancel_word_content;

    private MyIUiListener mIUiListener = new MyIUiListener();
    class MyIUiListener implements IUiListener {
        @Override
        public void onComplete(Object o) {
             Log.e("TAG","分享成功");
            getShareGold();
        }

        @Override
        public void onError(UiError uiError) {
            Log.e("TAG","分享出错");
        }

        @Override
        public void onCancel() {
            Log.e("TAG","分享取消");
        }

        @Override
        public void onWarning(int i) {

        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Tencent.onActivityResultData(requestCode, resultCode, data, mIUiListener);
        if (requestCode == Constants.REQUEST_API) {
            if (resultCode == Constants.REQUEST_QQ_SHARE || resultCode == Constants.REQUEST_QZONE_SHARE || resultCode == Constants.REQUEST_OLD_SHARE) {
                Tencent.handleResultData(data, mIUiListener);
            }
        }
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cancle_word);
        topbar = (TopBarView)findViewById(R.id.topbar);
        topbar.getRightView().setVisibility(View.GONE);
        topbar.setClickListener(this);
        topbar.getRightTextView().setText("排行榜");
        topbar.getRightTextView().setTextSize(15);
        topbar.getRightTextView().setClickable(true);
        topbar.getRightTextView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (CommonUtils.isEmpty(CustomApplication.loginModel.getToken()) || CustomApplication.isAutoLogin == true){
                    startActivity(new Intent(CancleWordActivity.this, LoginActivity.class));
                    finish();
                    return;
                }
                if (wordUserinfoModel != null){
                    Intent intent = new Intent(CancleWordActivity.this,GameRangeActivity.class);
                    intent.putExtra("appid",wordUserinfoModel.getAppid());
                    startActivity(intent);
                }

            }
        });
        textList = new ArrayList<WordModel>();
        answerList = new ArrayList<String>();
        answerList.add("");
        answerList.add("");
        answerList.add("");
        answerList.add("");
        allAnswerList = new ArrayList<Map<String,String>>();
        list = new ArrayList<String>();
        list.add("分享给微信好友");
        list.add("分享到微信朋友圈");
        list.add("分享给QQ好友");
        list.add("分享到QQ空间");
        //list.add("取消");
        initUI();
        getWordInfo();
        registerBoradcastReceiver();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(mBroadcastReceiver);
    }

    /**
     * 点击了返回导航按钮
     */
    @Override
    public void onBackClick() {
        //Toast.makeText(LoginActivity.this, "你点击了左侧按钮", Toast.LENGTH_LONG).show();
        finish();
    }

    /**
     * 点击了右边导航按钮
     */
    @Override
    public void onRightClick() {

    }

    private void initUI(){
        cancel_word_content = (RelativeLayout) findViewById(R.id.cancel_word_content);
        avi = (AVLoadingIndicatorView)findViewById(R.id.avi);
        cancel_word_menutip = (CircularProgressButton) findViewById(R.id.cancel_word_menutip);//提示
        cancel_word_menutip.setBackgroundColor(getResources().getColor(R.color.lightGreenColor));
        cancel_word_menutip.setStrokeColor(getResources().getColor(R.color.lightGreenColor));
        cancel_word_menutip.setText("提示");
        cancel_word_menureset = (CircularProgressButton) findViewById(R.id.cancel_word_menureset);//求助
        cancel_word_menureset.setBackgroundColor(getResources().getColor(R.color.orangeColor));
        cancel_word_menureset.setStrokeColor(getResources().getColor(R.color.orangeColor));
        cancel_word_menureset.setText("金币");
        cancel_word_menushare = (CircularProgressButton) findViewById(R.id.cancel_word_menushare);//分享
        cancel_word_menushare.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
        cancel_word_menushare.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
        cancel_word_menushare.setText("分享");

        cancel_word_firstline_1 = (CircularProgressButton) findViewById(R.id.cancel_word_firstline_1);
        cancel_word_firstline_2 = (CircularProgressButton) findViewById(R.id.cancel_word_firstline_2);
        cancel_word_firstline_3 = (CircularProgressButton) findViewById(R.id.cancel_word_firstline_3);
        cancel_word_firstline_4 = (CircularProgressButton) findViewById(R.id.cancel_word_firstline_4);
        cancel_word_firstline_5 = (CircularProgressButton) findViewById(R.id.cancel_word_firstline_5);
        cancel_word_firstline_6 = (CircularProgressButton) findViewById(R.id.cancel_word_firstline_6);
        cancel_word_firstline_7 = (CircularProgressButton) findViewById(R.id.cancel_word_firstline_7);

        cancel_word_secondline_1 = (CircularProgressButton) findViewById(R.id.cancel_word_secondline_1);
        cancel_word_secondline_2 = (CircularProgressButton) findViewById(R.id.cancel_word_secondline_2);
        cancel_word_secondline_3 = (CircularProgressButton) findViewById(R.id.cancel_word_secondline_3);
        cancel_word_secondline_4 = (CircularProgressButton) findViewById(R.id.cancel_word_secondline_4);
        cancel_word_secondline_5 = (CircularProgressButton) findViewById(R.id.cancel_word_secondline_5);
        cancel_word_secondline_6 = (CircularProgressButton) findViewById(R.id.cancel_word_secondline_6);
        cancel_word_secondline_7 = (CircularProgressButton) findViewById(R.id.cancel_word_secondline_7);

        cancel_word_thirdline_1 = (CircularProgressButton) findViewById(R.id.cancel_word_thirdline_1);
        cancel_word_thirdline_2 = (CircularProgressButton) findViewById(R.id.cancel_word_thirdline_2);
        cancel_word_thirdline_3 = (CircularProgressButton) findViewById(R.id.cancel_word_thirdline_3);
        cancel_word_thirdline_4 = (CircularProgressButton) findViewById(R.id.cancel_word_thirdline_4);
        cancel_word_thirdline_5 = (CircularProgressButton) findViewById(R.id.cancel_word_thirdline_5);
        cancel_word_thirdline_6 = (CircularProgressButton) findViewById(R.id.cancel_word_thirdline_6);
        cancel_word_thirdline_7 = (CircularProgressButton) findViewById(R.id.cancel_word_thirdline_7);

        cancel_word_fourthline_1 = (CircularProgressButton) findViewById(R.id.cancel_word_fourthline_1);
        cancel_word_fourthline_2 = (CircularProgressButton) findViewById(R.id.cancel_word_fourthline_2);
        cancel_word_fourthline_3 = (CircularProgressButton) findViewById(R.id.cancel_word_fourthline_3);
        cancel_word_fourthline_4 = (CircularProgressButton) findViewById(R.id.cancel_word_fourthline_4);
        cancel_word_fourthline_5 = (CircularProgressButton) findViewById(R.id.cancel_word_fourthline_5);
        cancel_word_fourthline_6 = (CircularProgressButton) findViewById(R.id.cancel_word_fourthline_6);
        cancel_word_fourthline_7 = (CircularProgressButton) findViewById(R.id.cancel_word_fourthline_7);

        cancel_word_fifthline_1 = (CircularProgressButton) findViewById(R.id.cancel_word_fifthline_1);
        cancel_word_fifthline_2 = (CircularProgressButton) findViewById(R.id.cancel_word_fifthline_2);
        cancel_word_fifthline_3 = (CircularProgressButton) findViewById(R.id.cancel_word_fifthline_3);
        cancel_word_fifthline_4 = (CircularProgressButton) findViewById(R.id.cancel_word_fifthline_4);
        cancel_word_fifthline_5 = (CircularProgressButton) findViewById(R.id.cancel_word_fifthline_5);
        cancel_word_fifthline_6 = (CircularProgressButton) findViewById(R.id.cancel_word_fifthline_6);
        cancel_word_fifthline_7 = (CircularProgressButton) findViewById(R.id.cancel_word_fifthline_7);

        cancel_word_sixthline_1 = (CircularProgressButton) findViewById(R.id.cancel_word_sixthline_1);
        cancel_word_sixthline_2 = (CircularProgressButton) findViewById(R.id.cancel_word_sixthline_2);
        cancel_word_sixthline_3 = (CircularProgressButton) findViewById(R.id.cancel_word_sixthline_3);
        cancel_word_sixthline_4 = (CircularProgressButton) findViewById(R.id.cancel_word_sixthline_4);
        cancel_word_sixthline_5 = (CircularProgressButton) findViewById(R.id.cancel_word_sixthline_5);


        cancel_word_firstline_1.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_firstline_1.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_firstline_2.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_firstline_2.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_firstline_3.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_firstline_3.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_firstline_4.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_firstline_4.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_firstline_5.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_firstline_5.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_firstline_6.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_firstline_6.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_firstline_7.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_firstline_7.setStrokeColor(getResources().getColor(R.color.wordBgColor));

        cancel_word_secondline_1.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_secondline_1.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_secondline_2.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_secondline_2.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_secondline_3.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_secondline_3.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_secondline_4.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_secondline_4.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_secondline_5.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_secondline_5.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_secondline_6.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_secondline_6.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_secondline_7.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_secondline_7.setStrokeColor(getResources().getColor(R.color.wordBgColor));

        cancel_word_thirdline_1.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_thirdline_1.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_thirdline_2.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_thirdline_2.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_thirdline_3.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_thirdline_3.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_thirdline_4.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_thirdline_4.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_thirdline_5.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_thirdline_5.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_thirdline_6.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_thirdline_6.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_thirdline_7.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_thirdline_7.setStrokeColor(getResources().getColor(R.color.wordBgColor));

        cancel_word_fourthline_1.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fourthline_1.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fourthline_2.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fourthline_2.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fourthline_3.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fourthline_3.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fourthline_4.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fourthline_4.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fourthline_5.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fourthline_5.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fourthline_6.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fourthline_6.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fourthline_7.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fourthline_7.setStrokeColor(getResources().getColor(R.color.wordBgColor));

        cancel_word_fifthline_1.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fifthline_1.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fifthline_2.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fifthline_2.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fifthline_3.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fifthline_3.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fifthline_4.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fifthline_4.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fifthline_5.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fifthline_5.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fifthline_6.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fifthline_6.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fifthline_7.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_fifthline_7.setStrokeColor(getResources().getColor(R.color.wordBgColor));

        cancel_word_sixthline_1.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_sixthline_1.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_sixthline_2.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_sixthline_2.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_sixthline_3.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_sixthline_3.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_sixthline_4.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_sixthline_4.setStrokeColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_sixthline_5.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
        cancel_word_sixthline_5.setStrokeColor(getResources().getColor(R.color.wordBgColor));


        cancel_word_tip = (TextView)findViewById(R.id.cancel_word_tip);
        cancel_word_gold = (TextView)findViewById(R.id.cancel_word_gold);

    }

    private void setText(String text, int line, int index, int visible, int select){
        switch (line){
            case 1:
                if (index == 1){
                    cancel_word_firstline_1.setText(text);
                    cancel_word_firstline_1.setVisibility(visible);
                    if (select == 1){
                        cancel_word_firstline_1.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_firstline_1.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_firstline_1.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_firstline_1.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 2){
                    cancel_word_firstline_2.setText(text);
                    cancel_word_firstline_2.setVisibility(visible);
                    if (select == 1){
                        cancel_word_firstline_2.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_firstline_2.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_firstline_2.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_firstline_2.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 3){
                    cancel_word_firstline_3.setText(text);
                    cancel_word_firstline_3.setVisibility(visible);
                    if (select == 1){
                        cancel_word_firstline_3.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_firstline_3.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_firstline_3.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_firstline_3.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 4){
                    cancel_word_firstline_4.setText(text);
                    cancel_word_firstline_4.setVisibility(visible);
                    if (select == 1){
                        cancel_word_firstline_4.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_firstline_4.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_firstline_4.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_firstline_4.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 5){
                    cancel_word_firstline_5.setText(text);
                    cancel_word_firstline_5.setVisibility(visible);
                    if (select == 1){
                        cancel_word_firstline_5.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_firstline_5.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_firstline_5.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_firstline_5.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 6){
                    cancel_word_firstline_6.setText(text);
                    cancel_word_firstline_6.setVisibility(visible);
                    if (select == 1){
                        cancel_word_firstline_6.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_firstline_6.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_firstline_6.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_firstline_6.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 7){
                    cancel_word_firstline_7.setText(text);
                    cancel_word_firstline_7.setVisibility(visible);
                    if (select == 1){
                        cancel_word_firstline_7.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_firstline_7.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_firstline_7.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_firstline_7.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }
                break;
            case 2:
                if (index == 1){
                    cancel_word_secondline_1.setText(text);
                    cancel_word_secondline_1.setVisibility(visible);
                    if (select == 1){
                        cancel_word_secondline_1.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_secondline_1.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_secondline_1.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_secondline_1.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 2){
                    cancel_word_secondline_2.setText(text);
                    cancel_word_secondline_2.setVisibility(visible);
                    if (select == 1){
                        cancel_word_secondline_2.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_secondline_2.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_secondline_2.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_secondline_2.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 3){
                    cancel_word_secondline_3.setText(text);
                    cancel_word_secondline_3.setVisibility(visible);
                    if (select == 1){
                        cancel_word_secondline_3.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_secondline_3.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_secondline_3.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_secondline_3.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 4){
                    cancel_word_secondline_4.setText(text);
                    cancel_word_secondline_4.setVisibility(visible);
                    if (select == 1){
                        cancel_word_secondline_4.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_secondline_4.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_secondline_4.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_secondline_4.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 5){
                    cancel_word_secondline_5.setText(text);
                    cancel_word_secondline_5.setVisibility(visible);
                    if (select == 1){
                        cancel_word_secondline_5.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_secondline_5.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_secondline_5.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_secondline_5.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 6){
                    cancel_word_secondline_6.setText(text);
                    cancel_word_secondline_6.setVisibility(visible);
                    if (select == 1){
                        cancel_word_secondline_6.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_secondline_6.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_secondline_6.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_secondline_6.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 7){
                    cancel_word_secondline_7.setText(text);
                    cancel_word_secondline_7.setVisibility(visible);
                    if (select == 1){
                        cancel_word_secondline_7.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_secondline_7.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_secondline_7.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_secondline_7.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }
                break;
            case 3:
                if (index == 1){
                    cancel_word_thirdline_1.setText(text);
                    cancel_word_thirdline_1.setVisibility(visible);
                    if (select == 1){
                        cancel_word_thirdline_1.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_thirdline_1.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_thirdline_1.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_thirdline_1.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 2){
                    cancel_word_thirdline_2.setText(text);
                    cancel_word_thirdline_2.setVisibility(visible);
                    if (select == 1){
                        cancel_word_thirdline_2.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_thirdline_2.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_thirdline_2.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_thirdline_2.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 3){
                    cancel_word_thirdline_3.setText(text);
                    cancel_word_thirdline_3.setVisibility(visible);
                    if (select == 1){
                        cancel_word_thirdline_3.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_thirdline_3.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_thirdline_3.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_thirdline_3.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 4){
                    cancel_word_thirdline_4.setText(text);
                    cancel_word_thirdline_4.setVisibility(visible);
                    if (select == 1){
                        cancel_word_thirdline_4.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_thirdline_4.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_thirdline_4.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_thirdline_4.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 5){
                    cancel_word_thirdline_5.setText(text);
                    cancel_word_thirdline_5.setVisibility(visible);
                    if (select == 1){
                        cancel_word_thirdline_5.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_thirdline_5.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_thirdline_5.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_thirdline_5.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 6){
                    cancel_word_thirdline_6.setText(text);
                    cancel_word_thirdline_6.setVisibility(visible);
                    if (select == 1){
                        cancel_word_thirdline_6.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_thirdline_6.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_thirdline_6.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_thirdline_6.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 7){
                    cancel_word_thirdline_7.setText(text);
                    cancel_word_thirdline_7.setVisibility(visible);
                    if (select == 1){
                        cancel_word_thirdline_7.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_thirdline_7.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_thirdline_7.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_thirdline_7.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }
                break;
            case 4:
                if (index == 1){
                    cancel_word_fourthline_1.setText(text);
                    cancel_word_fourthline_1.setVisibility(visible);
                    if (select == 1){
                        cancel_word_fourthline_1.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_fourthline_1.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_fourthline_1.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_fourthline_1.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 2){
                    cancel_word_fourthline_2.setText(text);
                    cancel_word_fourthline_2.setVisibility(visible);
                    if (select == 1){
                        cancel_word_fourthline_2.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_fourthline_2.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_fourthline_2.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_fourthline_2.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 3){
                    cancel_word_fourthline_3.setText(text);
                    cancel_word_fourthline_3.setVisibility(visible);
                    if (select == 1){
                        cancel_word_fourthline_3.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_fourthline_3.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_fourthline_3.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_fourthline_3.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 4){
                    cancel_word_fourthline_4.setText(text);
                    cancel_word_fourthline_4.setVisibility(visible);
                    if (select == 1){
                        cancel_word_fourthline_4.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_fourthline_4.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_fourthline_4.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_fourthline_4.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 5){
                    cancel_word_fourthline_5.setText(text);
                    cancel_word_fourthline_5.setVisibility(visible);
                    if (select == 1){
                        cancel_word_fourthline_5.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_fourthline_5.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_fourthline_5.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_fourthline_5.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 6){
                    cancel_word_fourthline_6.setText(text);
                    cancel_word_fourthline_6.setVisibility(visible);
                    if (select == 1){
                        cancel_word_fourthline_6.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_fourthline_6.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_fourthline_6.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_fourthline_6.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 7){
                    cancel_word_fourthline_7.setText(text);
                    cancel_word_fourthline_7.setVisibility(visible);
                    if (select == 1){
                        cancel_word_fourthline_7.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_fourthline_7.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_fourthline_7.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_fourthline_7.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }
                break;
            case 5:
                if (index == 1){
                    cancel_word_fifthline_1.setText(text);
                    cancel_word_fifthline_1.setVisibility(visible);
                    if (select == 1){
                        cancel_word_fifthline_1.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_fifthline_1.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_fifthline_1.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_fifthline_1.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 2){
                    cancel_word_fifthline_2.setText(text);
                    cancel_word_fifthline_2.setVisibility(visible);
                    if (select == 1){
                        cancel_word_fifthline_2.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_fifthline_2.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_fifthline_2.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_fifthline_2.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 3){
                    cancel_word_fifthline_3.setText(text);
                    cancel_word_fifthline_3.setVisibility(visible);
                    if (select == 1){
                        cancel_word_fifthline_3.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_fifthline_3.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_fifthline_3.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_fifthline_3.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 4){
                    cancel_word_fifthline_4.setText(text);
                    cancel_word_fifthline_4.setVisibility(visible);
                    if (select == 1){
                        cancel_word_fifthline_4.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_fifthline_4.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_fifthline_4.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_fifthline_4.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 5){
                    cancel_word_fifthline_5.setText(text);
                    cancel_word_fifthline_5.setVisibility(visible);
                    if (select == 1){
                        cancel_word_fifthline_5.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_fifthline_5.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_fifthline_5.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_fifthline_5.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 6){
                    cancel_word_fifthline_6.setText(text);
                    cancel_word_fifthline_6.setVisibility(visible);
                    if (select == 1){
                        cancel_word_fifthline_6.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_fifthline_6.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_fifthline_6.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_fifthline_6.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 7){
                    cancel_word_fifthline_7.setText(text);
                    cancel_word_fifthline_7.setVisibility(visible);
                    if (select == 1){
                        cancel_word_fifthline_7.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_fifthline_7.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_fifthline_7.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_fifthline_7.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }
                break;
            case 6:
                if (index == 1){
                    cancel_word_sixthline_1.setText(text);
                    cancel_word_sixthline_1.setVisibility(visible);
                    if (select == 1){
                        cancel_word_sixthline_1.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_sixthline_1.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_sixthline_1.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_sixthline_1.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 2){
                    cancel_word_sixthline_2.setText(text);
                    cancel_word_sixthline_2.setVisibility(visible);
                    if (select == 1){
                        cancel_word_sixthline_2.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_sixthline_2.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_sixthline_2.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_sixthline_2.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 3){
                    cancel_word_sixthline_3.setText(text);
                    cancel_word_sixthline_3.setVisibility(visible);
                    if (select == 1){
                        cancel_word_sixthline_3.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_sixthline_3.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_sixthline_3.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_sixthline_3.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 4){
                    cancel_word_sixthline_4.setText(text);
                    cancel_word_sixthline_4.setVisibility(visible);
                    if (select == 1){
                        cancel_word_sixthline_4.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_sixthline_4.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_sixthline_4.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_sixthline_4.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }else if (index == 5){
                    cancel_word_sixthline_5.setText(text);
                    cancel_word_sixthline_5.setVisibility(visible);
                    if (select == 1){
                        cancel_word_sixthline_5.setStrokeColor(getResources().getColor(R.color.limitBackgroundColor));
                        cancel_word_sixthline_5.setBackgroundColor(getResources().getColor(R.color.limitBackgroundColor));
                    }else {
                        cancel_word_sixthline_5.setStrokeColor(getResources().getColor(R.color.wordBgColor));
                        cancel_word_sixthline_5.setBackgroundColor(getResources().getColor(R.color.wordBgColor));
                    }
                }
                break;
        }
    }

    //点击文字
    public void onClickText(View view){
        if (isChecking == true){
            return;
        }
        int i = 0;
        switch (view.getId()){
            case R.id.cancel_word_firstline_1:
                i = 1;
                break;
            case R.id.cancel_word_firstline_2:
                i = 2;
                break;
            case R.id.cancel_word_firstline_3:
                i = 3;
                break;
            case R.id.cancel_word_firstline_4:
                i = 4;
                break;
            case R.id.cancel_word_firstline_5:
                i = 5;
                break;
            case R.id.cancel_word_firstline_6:
                i = 6;
                break;
            case R.id.cancel_word_firstline_7:
                i = 7;
                break;

            case R.id.cancel_word_secondline_1:
                i = 8;
                break;
            case R.id.cancel_word_secondline_2:
                i = 9;
                break;
            case R.id.cancel_word_secondline_3:
                i = 10;
                break;
            case R.id.cancel_word_secondline_4:
                i = 11;
                break;
            case R.id.cancel_word_secondline_5:
                i = 12;
                break;
            case R.id.cancel_word_secondline_6:
                i = 13;
                break;
            case R.id.cancel_word_secondline_7:
                i = 14;
                break;

            case R.id.cancel_word_thirdline_1:
                i = 15;
                break;
            case R.id.cancel_word_thirdline_2:
                i = 16;
                break;
            case R.id.cancel_word_thirdline_3:
                i = 17;
                break;
            case R.id.cancel_word_thirdline_4:
                i = 18;
                break;
            case R.id.cancel_word_thirdline_5:
                i = 19;
                break;
            case R.id.cancel_word_thirdline_6:
                i = 20;
                break;
            case R.id.cancel_word_thirdline_7:
                i = 21;
                break;

            case R.id.cancel_word_fourthline_1:
                i = 22;
                break;
            case R.id.cancel_word_fourthline_2:
                i = 23;
                break;
            case R.id.cancel_word_fourthline_3:
                i = 24;
                break;
            case R.id.cancel_word_fourthline_4:
                i = 25;
                break;
            case R.id.cancel_word_fourthline_5:
                i = 26;
                break;
            case R.id.cancel_word_fourthline_6:
                i = 27;
                break;
            case R.id.cancel_word_fourthline_7:
                i = 28;
                break;

            case R.id.cancel_word_fifthline_1:
                i = 29;
                break;
            case R.id.cancel_word_fifthline_2:
                i = 30;
                break;
            case R.id.cancel_word_fifthline_3:
                i = 31;
                break;
            case R.id.cancel_word_fifthline_4:
                i = 32;
                break;
            case R.id.cancel_word_fifthline_5:
                i = 33;
                break;
            case R.id.cancel_word_fifthline_6:
                i = 34;
                break;
            case R.id.cancel_word_fifthline_7:
                i = 35;
                break;

            case R.id.cancel_word_sixthline_1:
                i = 36;
                break;
            case R.id.cancel_word_sixthline_2:
                i = 37;
                break;
            case R.id.cancel_word_sixthline_3:
                i = 38;
                break;
            case R.id.cancel_word_sixthline_4:
                i = 39;
                break;
            case R.id.cancel_word_sixthline_5:
                i = 40;
                break;
        }
        dealWithText(i);
    }

    private void dealWithText(int i){
        if (textList != null && textList.size() > 0){
            WordModel m = textList.get(i-1);
            if (m.getSelect() == 1){
                m.setSelect(0);
            }else {
                m.setSelect(1);
            }
            Log.e("TAG","现在的状态："+m.getSelect()+"\n");
            textList.set(i-1,m);
            setText(m.getText(),(i-1)/7+1,(i-1)%7+1,m.getVisible(),m.getSelect());
            checkAnswer(i-1,m.getSelect(),m.getText());
        }
    }

    //点击菜单
    public void onClickMenu(View view){
        switch (view.getId()){
            case R.id.cancel_word_menutip:
                getTip();
                break;
            case R.id.cancel_word_menureset:
                signDo();
                //getWordInfo();
                break;
            case R.id.cancel_word_menushare:
                share(view);
                break;
        }
    }

    private void share(View v){
        /*
        menuWindow = new PublishSelectPicPopupWindow(CancleWordActivity.this,itemsOnClick,list);
        // 显示窗口
        menuWindow.showAtLocation(v,
                Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        */
        ActionSheetDialog actionSheetDialog = new ActionSheetDialog(CancleWordActivity.this)
                .builder()
                .setTitle("请选择")
                .setCancelable(false)
                .setCanceledOnTouchOutside(true);
        for (String s : list){
            actionSheetDialog.addSheetItem(s, null, new ActionSheetDialog.OnSheetItemClickListener() {
                @Override
                public void onClick(int which) {
                    if (which == 1){
                        //分享给微信好友
                        String des = "分享自微句";
                        if (shareDes != null){
                            des = shareDes;
                        }
                        shareToWX(1,url,content,des);
                    }else if (which == 2){
                        //分享到朋友圈
                        String title = "【成语消消】";
                        if(shareDes != null){
                            title += shareDes;
                        }
                        shareToWX(0,url,title,content);
                    }else if (which == 3){
                        //分享到qq
                        String des = "分享自微句";
                        if (shareDes != null){
                            des = shareDes;
                        }
                        shareToQQ(0,url,content,des);
                    }else if (which == 4){
                        //qq空间
                        String des = "分享自微句";
                        if (shareDes != null){
                            des = shareDes;
                        }
                        shareToQQ(1,url,des,content);
                    }
                }
            });
        }
        actionSheetDialog.show();
    }

    //分享到qq
    private Bundle params;
    private void shareToQQ(int type, String url,String title,String content){
        params = new Bundle();
        if (type == 0){//分享给QQ好友
            params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
            params.putString(QQShare.SHARE_TO_QQ_TITLE, title);// 标题
            params.putString(QQShare.SHARE_TO_QQ_SUMMARY, content);// 摘要
            params.putString(QQShare.SHARE_TO_QQ_TARGET_URL,url);// 内容地址
            params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL,"http://image.daydayrise.net/360@2x.png");// 网络图片地址
            params.putString(QQShare.SHARE_TO_QQ_EXT_INT, "");//其它附加功能
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    CustomApplication.mTencent.shareToQQ(CancleWordActivity.this, params, mIUiListener);
                }
            });
        }else {
            //分享到QQ空间
            params.putInt(QzoneShare.SHARE_TO_QZONE_KEY_TYPE,QzoneShare.SHARE_TO_QZONE_TYPE_IMAGE_TEXT);
            params.putString(QzoneShare.SHARE_TO_QQ_TITLE, title);// 标题
            params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, content);// 摘要
            params.putString(QzoneShare.SHARE_TO_QQ_TARGET_URL,url);// 内容地址
            ArrayList<String> imgUrlList = new ArrayList<>();
            imgUrlList.add("http://image.daydayrise.net/360@2x.png");
            params.putStringArrayList(QzoneShare.SHARE_TO_QQ_IMAGE_URL,imgUrlList);// 图片地址
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    CustomApplication.mTencent.shareToQzone(CancleWordActivity.this, params, mIUiListener);
                }
            });
        }

    }

    public void getWordInfo(){
        avi.show();
        answerList.set(0,"");
        answerList.set(1,"");
        answerList.set(2,"");
        answerList.set(3,"");
        allAnswerList.clear();
        final HashMap<String, String> map = new HashMap<String, String>();
        map.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
        HttpsUtils.miniAppDo(map, "miniapp/appidlianlian/getuserconnectwordinfo.do", new HttpCallBack() {// usersign
            @Override
            public void onSuccess(String data) {
                avi.hide();
                Log.e("TAG","成语消消："+data+"\n");
                CommonModel commonModel = GsonTools.getCommonModel(data);
                if (commonModel.getFlag().equals("1")){
                    //ToastUtil.show(GuessWordActivity.this,commonModel.getMsg());
                    wordUserinfoModel = GsonTools.getWordUserinfoModel(data);
                    if (wordUserinfoModel != null){
                        cancel_word_gold.setText(""+wordUserinfoModel.getGoldcount());
                        topbar.getTitleView().setText("第 "+(wordUserinfoModel.getPlaylevel()+1)+" 关");
                    }
                    wordlistModelList = GsonTools.getWordlistModel(data);
                    if (wordlistModelList != null){
                        Log.e("TAG","wordlistModelList:"+wordlistModelList.size()+"\n");
                        WordlistModel m = wordlistModelList.get(0);
                        cancel_word_tip.setText("【提示】"+m.getIntroduce());
                        shareDes = m.getIntroduce();
                    }
                    JSONArray wordList = GsonTools.getCancleWordInfo(data);
                    textList.clear();
                    if (wordList != null){
                        Log.e("TAG","wordList:"+wordList.length());
                        for (int i = 0; i < wordList.length(); i++){
                            try{
                                String text = wordList.getString(i);
                                WordModel wordModel = new WordModel();
                                wordModel.setSelect(0);
                                wordModel.setVisible(View.VISIBLE);
                                wordModel.setText(text);
                                textList.add(wordModel);
                                setText(text,i/7+1,i%7+1,View.VISIBLE,0);
                            }catch (Exception e){

                            }
                        }
                    }
                    Animation animation = AnimationUtils.loadAnimation(CancleWordActivity.this, R.anim.pushfromleft);
                    cancel_word_content.startAnimation(animation);
                }else {
                    CustomApplication.showTip(commonModel,CancleWordActivity.this);
                    //ToastUtil.show(GuessWordActivity.this,commonModel.getMsg());
                }
            }
            @Override
            public void onError(String msg) {
               avi.hide();
            }
        });

    }

    //检测答案
    private void checkAnswer(int index, int select, String text){
        //添加答案
        if (select == 0){
            int ii = answerList.indexOf(index+"");
            answerList.set(ii,"");
        }else {
            for (int i = 0; i < answerList.size(); i++){
                if (answerList.get(i).length() == 0){
                    answerList.set(i,index+"");
                    break;
                }
            }
        }
        //本地检测
        int count = 0;
        String word = "";
        for (int i = 0; i < answerList.size(); i++){
            if (answerList.get(i).length() > 0){
                int ii = Integer.valueOf(answerList.get(i));
                WordModel w = textList.get(ii);
                word += w.getText();
                count++;
            }
        }
        if (count == answerList.size()){
            if (isChecking == true){
                return;
            }
            isChecking = true;
//            String word = CommonUtils.listToString(answerList);
//            word = word.replaceAll(",","");
//            word = word.replaceAll(" ","");
            Log.e("TAG","检测答案:"+word+"\n");
            int currentIndex = allAnswerList.size();
            if (currentIndex == wordlistModelList.size()){
                return;
            }
            Log.e("TAG","检测答案索引:"+currentIndex+"\n");
            WordlistModel wordlistModel = wordlistModelList.get(currentIndex);
            if (word.equals(wordlistModel.getWord())){
                HashMap<String,String> map = new HashMap<String, String>();
                map.put("id",wordlistModel.getId()+"");
                map.put("word",wordlistModel.getWord());
                allAnswerList.add(map);
                if (allAnswerList.size() != wordlistModelList.size()){
                    wordlistModel = wordlistModelList.get(allAnswerList.size());
                    cancel_word_tip.setText("【提示】"+wordlistModel.getIntroduce());
                    shareDes = wordlistModel.getIntroduce();
                }
                for (String s : answerList){
                    int ii = Integer.valueOf(s);
                    WordModel m = textList.get(ii);
                    m.setVisible(View.INVISIBLE);
                    textList.set(ii,m);
                    setText(m.getText(),ii/7+1,ii%7+1,View.INVISIBLE,0);
                }
                answerList.set(0,"");
                answerList.set(1,"");
                answerList.set(2,"");
                answerList.set(3,"");
                if (allAnswerList.size() == wordlistModelList.size()){
                    //在线检测
                    checkAnswerOnline();
                }
                isChecking = false;
            }else {
                ToastUtil.show(CancleWordActivity.this,"答案错误");
                new Handler().postDelayed(new Runnable(){
                    public void run() {
                        for (int i = 0; i < answerList.size(); i++){
                            int index = Integer.valueOf(answerList.get(i));
                            dealWithText(index+1);
                        }
                        isChecking = false;
                    }
                }, 500);   //0.5秒
            }

        }


    }

    //在线检测答案
    private void checkAnswerOnline(){
        final Map<String, String> map = new HashMap<String, String>();
        com.alibaba.fastjson.JSONArray jsonArray = new com.alibaba.fastjson.JSONArray();
        for (int i = 0; i < allAnswerList.size(); i++){
            Map<String, String> m = allAnswerList.get(i);
            JSONObject jsonObject = new JSONObject(m);
            jsonArray.add(jsonObject);
        }
        map.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
        map.put("wordjson",jsonArray.toJSONString());
        Log.e("TAG","请求参数："+map+"\n");
        HttpsUtils.miniAppDo(map, "miniapp/appidlianlian/checkallwordsanswer.do", new HttpCallBack() {// usersign
            @Override
            public void onSuccess(String data) {
                Log.e("TAG","在线答案："+data+"\n");
                CommonModel commonModel = GsonTools.getCommonModel(data);
                if (commonModel.getFlag().equals("1")){
                    allAnswerList.clear();
                    getWordInfo();
                }else {
                    ToastUtil.show(CancleWordActivity.this,commonModel.getMsg());
                }
            }
            @Override
            public void onError(String msg) {

            }
        });
    }

    //获取提示
    private void getTip(){
        if (wordUserinfoModel == null){
            return;
        }
        if (allAnswerList.size() < wordlistModelList.size()){
            if (isGettingTip == true){
                return;
            }
            isGettingTip = true;
            avi.show();
            WordlistModel wordlistModel = wordlistModelList.get(allAnswerList.size());
            final HashMap<String, String> map = new HashMap<String, String>();
            map.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
            map.put(APIKey.idKey,wordlistModel.getId()+"");
            HttpsUtils.miniAppDo(map, "miniapp/appidlianlian/getonewordtip.do", new HttpCallBack() {// usersign
                @Override
                public void onSuccess(String data) {
                    avi.hide();
                    Log.e("TAG","提示："+data+"\n");
                    CommonModel commonModel = GsonTools.getCommonModel(data);
                    if (commonModel.getFlag().equals("1")){
                        //ToastUtil.show(CancleWordActivity.this,commonModel.getMsg());
                        wordUserinfoModel = GsonTools.getWordUserinfoModel(data);
                        if (wordUserinfoModel != null){
                            cancel_word_gold.setText(""+wordUserinfoModel.getGoldcount());
                            topbar.getTitleView().setText("第 "+(wordUserinfoModel.getPlaylevel()+1)+" 关");
                        }
                        WordlistModel wordModel = GsonTools.getWordModel(data);
                        ToastUtil.show(CancleWordActivity.this,wordModel.getWord());
                    }else {
                        ToastUtil.show(CancleWordActivity.this,commonModel.getMsg());
                    }
                    isGettingTip = false;
                }
                @Override
                public void onError(String msg) {
                    isGettingTip = false;
                    avi.hide();
                }
            });
        }
    }

    // 为弹出窗口实现监听类
    private View.OnClickListener itemsOnClick = new View.OnClickListener() {

        public void onClick(View v) {
            menuWindow.dismiss();
            switch (v.getId()) {
                case R.id.first_button://分享给微信好友
                    String des = "分享自微句";
                    if (shareDes != null){
                        des = shareDes;
                    }
                    shareToWX(1,url,content,des);
                    break;
                case R.id.second_button://分享到微信朋友圈
                    String title = "【成语消消】";
                    if(shareDes != null){
                        title += shareDes;
                    }
                    shareToWX(0,url,title,content);
                    break;
                case R.id.third_button:
                    break;
                default:
                    break;
            }

        }
    };

    //分享到微信
    private void shareToWX(int type,String url,String title,String content){
        //初始化一个WXWebpageObject对象，填写url
        WXWebpageObject webpage = new WXWebpageObject();
        webpage.webpageUrl = url;
        //用WXWebpageObject对象初始化一个WXMediaMessage对象，填写标题、描述
        WXMediaMessage msg = new WXMediaMessage(webpage);
        msg.title = title;
        msg.description = content;
        Bitmap thumb = BitmapFactory.decodeResource(getResources(),R.mipmap.icon);
        msg.thumbData = CommonUtils.bitmapToByteArray(thumb,true);
        //构成一个Req
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.message = msg;
        req.scene = type==0 ? SendMessageToWX.Req.WXSceneTimeline:SendMessageToWX.Req.WXSceneSession;
        CustomApplication.mWxApi.sendReq(req);

    }

    private void getShareGold(){
        final HashMap<String, String> map = new HashMap<String, String>();
        map.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
        String url = "miniapp/"+wordUserinfoModel.getAppid()+"/usershare.do";
        HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
            @Override
            public void onSuccess(String data) {
                final CommonModel commonModel = GsonTools.getCommonModel(data);
                if (commonModel.getFlag().equals("1")){
                    wordUserinfoModel = GsonTools.getWordUserinfoModel(data);
                    new Handler().postDelayed(new Runnable(){
                        public void run() {
                            ToastUtil.show(CancleWordActivity.this,commonModel.getMsg());
                            cancel_word_gold.setText(""+wordUserinfoModel.getGoldcount());
                        }
                    }, 10);
                }
            }

            @Override
            public void onError(String msg) {

            }
        });
    }

    /**
     * 广播接收者
     * @author Gordon
     */
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(BroadcastDefine.WX_Share_Result)) {
                //微信分享成功
                getShareGold();
            }
        }
    };

    /**
     * 注册广播
     * @author Gordon
     */
    public void registerBoradcastReceiver(){
        IntentFilter myIntentFilter = new IntentFilter();
        //添加接收广播类型
        myIntentFilter.addAction(BroadcastDefine.WX_Share_Result);
        //注册广播
        registerReceiver(mBroadcastReceiver, myIntentFilter);
    }

    private void signDo(){
        if (wordUserinfoModel == null){
            return;
        }
        avi.show();
        final HashMap<String, String> map = new HashMap<String, String>();
        map.put(APIKey.tokenKey,CustomApplication.loginModel.getToken());
        String url = "miniapp/"+wordUserinfoModel.getAppid()+"/usersign.do";
        HttpsUtils.miniAppDo(map, url, new HttpCallBack() {// usersign
            @Override
            public void onSuccess(String data) {
                avi.hide();
                Log.e("TAG",data);
                final CommonModel commonModel = GsonTools.getCommonModel(data);
                if (commonModel.getFlag().equals("1")){
                    wordUserinfoModel = GsonTools.getWordUserinfoModel(data);
                    new Handler().postDelayed(new Runnable(){
                        public void run() {
                            ToastUtil.show(CancleWordActivity.this,commonModel.getMsg());
                            cancel_word_gold.setText(""+wordUserinfoModel.getGoldcount());
                        }
                    }, 10);
                }else {
                    ToastUtil.show(CancleWordActivity.this,"你已领取");
                }
            }
            @Override
            public void onError(String msg) {
                avi.hide();
            }
        });
    }

}
